<script setup>
import {
    Management,
    Promotion,
    UserFilled,
    User,
    Crop,
    EditPen,
    SwitchButton,
    CaretBottom,
    Filter,
    Loading,
    Mug,
    Pear,
    Watermelon,
    Sunny,
    ChromeFilled,
    Compass
} from '@element-plus/icons-vue'
import avatar from '@/assets/default.png'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import {logout} from "@/api/quit.js";
import router from "@/router/index.js";
import {ElMessage} from "element-plus";

const userStore = useUserStore()

// 使用 store 中的数据

const userId = userStore.userId
const userName = userStore.userName

//退出登录
const quit=()=>{
  try {
    //后端发送退出请求
    logout()
    //清除用户信息
    userStore.clearUserData()
    //跳转到主页
    router.push('/index')
    //消息提示
    ElMessage.success("退出成功")
  }catch (err){
    ElMessage.error("退出失败："+err.message)

  }

}


//跳转到个人信息页面
const goInfo = () => {
  window.open(`/user/userInfo?userId=${userId}`, '_blank');
  console.log("是否获取到Id" + userId)
};
</script>

<template>
    <!-- element-plus中的容器 -->
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            <div class="el-aside__logo"></div>
            <!-- element-plus的菜单标签 -->
            <el-menu active-text-color="#ffd04b" background-color="#9ac7f7" text-color="#fff" router>
              <el-sub-menu>
                <template #title>
                  <el-icon>
                    <Watermelon />
                  </el-icon>
                  <span>赛事管理</span>
                </template>
                <el-menu-item index="/match/competition">
                  <el-icon class="is-loading">
                    <Compass />
                  </el-icon>
                  <span>赛事页面</span>
                </el-menu-item>
                <el-menu-item index="/manage/information">
                  <el-icon>
                    <Mug />
                  </el-icon>
                  <span>项目信息</span>
                </el-menu-item>
              </el-sub-menu>
                <el-menu-item index="/manage/userList">
                  <el-icon>
                    <Mug />
                  </el-icon>
                  <span>用户管理</span>
                </el-menu-item>
              <el-menu-item index="/match/scoreManage">
                <el-icon>
                  <Mug />
                </el-icon>
                <span>成绩管理</span>
              </el-menu-item>
                <el-menu-item index="/manage/collegeList">
                    <el-icon>
                        <Pear />
                    </el-icon>
                    <span>学院管理</span>
                </el-menu-item>
            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header>
                <div>用户昵称：<strong>{{ userName}}</strong></div>
                <!-- 下拉菜单 -->
                 <!-- command：条目被点击后会触发，在事件函数上可以声明一个参数，接收条目对应的指令 -->
                <el-dropdown placement="bottom-end" @command="handleCommand">
                    <span class="el-dropdown__box">
                        <el-avatar :src="avatar" />
                        <el-icon>
                            <CaretBottom />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="info" :icon="User" @click="goInfo">基本资料</el-dropdown-item>
                            <el-dropdown-item command="resetPassword" :icon="EditPen">重置密码</el-dropdown-item>
                            <el-dropdown-item command="logout" :icon="SwitchButton" @click="quit">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <!-- <div style="width: 1290px; height: 570px;border: 1px solid red;">
                    内容展示区
                </div> -->

                <router-view></router-view>
            </el-main>
            <!-- 底部区域 -->
            <el-footer>团队合作项目</el-footer>
        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;

    .el-aside {
        background-color: #9ac7f7;

        &__logo {
            height: 120px;
            background: url('@/assets/logo.png') no-repeat center / 240px auto;
        }

        .el-menu {
            border-right: none;
        }
    }

    .el-header {
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #999;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #666;
    }
}
</style>